package com.call.data;

import com.call.Constants;
import com.call.data.PhoneNumberListData.TableColumns;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import android.util.Log;

public class OperationData extends ListByDatabase {
	public static class TableColumns implements BaseColumns
	{
		public static String PhoneNumber = "PhoneNumber";
		public static String AddTime = "ItemAddTime";
		public static String Type = "type";
	}
	private static class DatabaseHelper extends SQLiteOpenHelper {

		private String m_strTableName;
        DatabaseHelper(Context context, String tableName) {
            super(context, Constants.DATABASE_NAME, null, Constants.DATABASE_VERSION);
            m_strTableName = tableName;
        }
        
        @Override
        public void onCreate(SQLiteDatabase db) {
        	db.execSQL("DROP TABLE IF EXISTS " + m_strTableName);
            db.execSQL("CREATE TABLE " + m_strTableName + " ("
                    + TableColumns._ID + " INTEGER PRIMARY KEY,"
                    + TableColumns.PhoneNumber + " INTEGER,"
                    + TableColumns.AddTime + " LONG,"
                    + TableColumns.Type + " SHORT"
                    + ");");
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.w(Constants.Tag, "Upgrading database from version " + oldVersion + " to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS " + m_strTableName);
            onCreate(db);
        }
    }
	/*
	 * no need to implement as singleton scheme.
	 * provide two interface.
	 */
	public OperationData(SQLiteOpenHelper objDBHelper, String strTableName) {
		super(objDBHelper, strTableName);
	}
	public static OperationData GetOperationData(Context context, String strTableName)
	{
		DatabaseHelper dataBaseHelper = new DatabaseHelper(context, strTableName);
		return new OperationData(dataBaseHelper, strTableName);
	}

}
